﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMA.GENTEv1.Dados;

namespace SMA.GENTEv1
{
    public class TipoEmail
    {
        #region Variaveis Membro
        private int _idTipoEmail;
        private string _descricao;
        private GENTEEntities _context;
        #endregion

        #region Propriedades
        public int IdTipoEmail
        {
            get { return _idTipoEmail; }
            set { _idTipoEmail = value; }
        }
        public string Descricao
        {
            get { return _descricao; }
            set { _descricao = value; }
        }
        #endregion

        #region Contrutores
        public TipoEmail()
        {
            try
            {
                _context = new GENTEEntities();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public TipoEmail(int idTipoEmail)
        {
            try
            {
                _context = new GENTEEntities();
                Carregar(idTipoEmail);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Privados
        private void Carregar(int idTipoEmail)
        {
            try
            {
                var consulta = from tp in _context.tab_tipo_email
                               where tp.id_tipo_email == idTipoEmail
                               select tp;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    this._idTipoEmail = list.id_tipo_email;
                    this._descricao = list.descricao;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Publicos
        public List<TipoEmail> SelectAll()
        {
            try
            {
                List<TipoEmail> listTipoEmail = new List<TipoEmail>();

                var consulta = from tp in _context.tab_tipo_email
                               select tp;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    TipoEmail tipoEmail = new TipoEmail();
                    tipoEmail.IdTipoEmail = list.id_tipo_email;
                    tipoEmail.Descricao = list.descricao;

                    listTipoEmail.Add(tipoEmail);
                }

                return listTipoEmail;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        

        
    }
}
